<template>
    <div class="defaultModalList-wrapper">
        <section v-if="type == 'defaultSelect'">切换默认搜索项目</section>
        <div class="d-menu" >
            <div class="d-list" v-for="(list, index) in defaulSelectItems" :key="list.id" @click="choice(list, index)"
                :class="[activeIndex == index ? 'active' : '']">{{ list.label }}</div>
        </div>
    </div>
</template>

<script>
// import { defaulSelectItems } from '../const';
export default {
    props: {
        type: {
            type: String,
            require: true
        },
        defaults:{
            type:Array,
            default(){
                return []
            }
        }
    },
    components: {

    },
    data () {
        return {
            activeIndex: null,
        }
    },
    computed: {
        defaulSelectItems(){
            return this.defaults
        }
    },
    created () {

    },
    mounted () {
   
    },
    watch:{

    },
    methods: {
        setDefaulSelectItems(defaulSelectItems){
            this.defaulSelectItems = defaulSelectItems

            if (this.type !== 'defaultSelect') return
            let hasDefaultIndex = this.defaulSelectItems.findIndex(el => el.defalut == true)
            if (hasDefaultIndex != -1) {
                // 选项列表有默认选中的项目
                this.activeIndex = hasDefaultIndex
                this.$emit('close', this.defaulSelectItems[hasDefaultIndex])
            } else {
                // 选项列表无默认选中项目默认第一项是查询条件
                this.activeIndex = 0
                this.$emit('close', this.defaulSelectItems[0])
            }
        },
        choice (list, i) {
            if (this.type == 'defaultSelect') {
                this.activeIndex = i
                this.$emit('close', list)
            }

            if (this.type == 'fieldList') {

                this.$emit('close', list)
            }

        }
    },
    activated () { },
}
</script>

<style lang='scss' scoped>
@import '../varConfig.scss';

.defaultModalList-wrapper {
    section {
        color: #8A8E99;
        font-size: 14px;
        margin-bottom: 15px;
        padding: 0 10px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-weight: bolder;
    }

    .d-menu {
        .d-list {
            padding: 0 20px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            height: 35px;
            line-height: 35px;
            font-size: 14px;
            color: rgb(37, 43, 58);
            cursor: pointer;

            &:hover {
                color: $hoverFontColor;
                background-color: #f2f5fc;
            }

            &.active {
                color: #fff;
                background-color: #5e80e0;
            }
        }
    }
}
</style>